import { ref, computed , onMounted } from 'vue'
import { defineStore } from 'pinia'
import {getProducts} from '../api/product'
export const useProductStore = defineStore('product', () => {
    const products = ref([])
    onMounted(() => {
        getProducts().then((res)=>{
            console.log(res)
            products.value= res
        })
        
    })
    const reduceNum=(id)=>{
        products.value.forEach(item=>{
            if(item.id===id){
                item.number--
            }
        })
    }

    return { products, reduceNum }
})
